package com.tangr.adapterapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.tangr.normaladapter.abslistview.MultiItemAdapter;
import com.tangr.normaladapter.abslistview.MultiItemTypeSupport;
import com.tangr.normaladapter.abslistview.NormalAdapter;
import com.tangr.normaladapter.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class ListViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView lv = (ListView) findViewById(R.id.lv);
        List<String> list = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++){
            list.add("" + (char) i);
        }
//        lv.setAdapter(new NormalAdapter<String>(this,list,R.layout.list_item) {
//            @Override
//            public void setView(ViewHolder vh, String item) {
//                vh.setText(R.id.item_tv,item);
//                vh.setImage(R.id.item_iv,R.mipmap.ic_launcher);
//            }
//        });
        lv.setAdapter(new MultiItemAdapter<String>(this, list, new MultiItemTypeSupport<String>() {
            @Override
            public int getLayoutId(int type) {
                if (type==0)
                    return R.layout.list_item;
                return R.layout.list_item1;
            }

            @Override
            public int getViewTypeCount() {
                return 2;
            }

            @Override
            public int getItemViewType(int position, String s) {
                if (position%2==0)
                    return 0;
                return 1;
            }
        }) {
            @Override
            public void setView(ViewHolder vh, String item) {
                if(vh.getLayoutId()==R.layout.list_item){
                    vh.setText(R.id.item_tv,item);
                    vh.setImage(R.id.item_iv, R.mipmap.ic_launcher);
                }else {
                    vh.setText(R.id.item_tv,item);
                    vh.setImage(R.id.item_iv, R.mipmap.ic_launcher);
                }
            }
        });
    }
}
